// 登录接口
import { login } from '@/api/login.js'
// 导入message插件
import { Message } from 'element-ui'
import store from '@/router/index.js'
const state = {
  token: ''
}
const mutations = {
  setToken (state, value) {
    state.token = value
  },
  // // 退出登录
  logout (state, value) {
    state.token = value
    store.router.push('/loghin')
  }
}

const actions = {
  // 发起token请求
  async getToken ({ commit }, value) {
    const res = await login(value)
    commit('setToken', res.data.token)

    // commit('setUserId')
    // console.log(res.msg)
    if (res.msg === 'ok') {
      Message.success('登录成功！')
      store.push('/layout/discipline')
    } else {
      Message.error(res.message)
    }
    // console.log(res)
  }
}
const getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
